package com.example.userservice.logger;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

public class BizLogger {
    private static final Logger logger = LoggerFactory.getLogger("BIZ_LOGGER");
    /**
     * 带描述信息的版本
     * @param bizType 业务类型
     * @param bizId 业务ID
     * @param operation 操作类型
     * @param success 是否成功
     * @param msg 描述信息
     */
    public static void log(String bizType, Long bizId, String operation,
                           boolean success, String msg) {
        String bizIdStr = String.valueOf(bizId);
        MDC.put("bizId", bizIdStr);
        String message = String.format("type=%s|userId=%s|operation=%s|success=%s|msg=%s",
                bizType, bizIdStr, operation, success, msg);

        if (success) {
            logger.info(message);
        } else {
            logger.error(message);
        }
        MDC.remove("bizId");
    }
}
